home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH06 / PROJ6_1.ASM < prev    next >
Encoding:
Assembly Source File  |  1996-02-04  |  2.6 KB  |  108 lines

  1. ; PROJ6_1.ASM
  2. ; Project #1: Write a short "GetLine routine that reads up to 80 characters
  3. ; from the user and places the characters in successive locations in a buffer
  4. ; in the data segment.  You can call the "GETChar" and "PUTChar" subroutines
  5. ; provided in this code to read characters and write characters.
  6. ;
  7. ; Terminate user input when you encounter a carriage return (ASCII code=0Dh)
  8. ; or after reading the 80th character.  Place a zero in the buffer where the
  9. ; carriage return would have went or in the 81st character position.
  10. ;
  11. ; Count the number of characters read by the user and return this count to
  12. ; the caller in the CX register.
  13. ;
  14. ; Be sure to delete all project explanations from the comments in this
  15. ; program before you submit it as your own work.  Of course, you are
  16. ; expected to *fully* comment your own code.
  17.  
  18. dseg        segment    para public 'data'
  19.  
  20. ; Put the declaration for "BUFFER" (the input buffer) here.  It must
  21. ; support at least 81 characters.  You should put any other variable
  22. ; declarations you need here as well.
  23.  
  24. dseg        ends
  25.  
  26.  
  27.  
  28. cseg        segment    para public 'code'
  29.         assume    cs:cseg, ds:dseg
  30.  
  31.  
  32. ; GetChar is a subroutine you can call to read a single key from the
  33. ; keyboard.  It returns the character it reads in the AL register.
  34.  
  35. GetChar        proc
  36.         mov    ah, 0        ;BIOS call to read a key.
  37.         int    16h
  38.         ret
  39. GetChar        endp
  40.  
  41.  
  42. ; PutChar prints the character in the AL register to the display.
  43.  
  44. PutChar        proc
  45.         push    ax        ;Preserve value in AH
  46.         mov    ah, 0eh        ;BIOS call to print a character.
  47.         int    10h
  48.         pop    ax        ;Restore AH's value.
  49.         ret
  50. PutChar        endp
  51.  
  52.  
  53.  
  54.  
  55. ; GetLine- Here's the subroutine you've got to write.
  56. ;       Besure to preserve all register you modify using push and pop
  57. ;       instructions (do not preserve CX, though, since this contains
  58. ;       a return value).
  59.  
  60. GetLine        proc
  61.  
  62. ; ****************   Insert your code here.  **************************
  63.  
  64.         ret
  65. GetLine        endp
  66.  
  67.  
  68.  
  69.  
  70. Main        proc
  71.         mov    ax, dseg
  72.         mov    ds, ax
  73.         mov    es, ax
  74.  
  75. ; Main program to get the GetLine routine:
  76.  
  77.         call    GetLine
  78.  
  79.  
  80. ; Print the data read by GetLine
  81.  
  82.         lea    bx, Buffer
  83. PrintLoop:    mov    al, [bx]
  84.         call    PutChar
  85.         inc    bx
  86.         loop    PrintLoop
  87.  
  88.         mov    al, 0dh            ;Print a carriage return
  89.         call    PutChar            ; and a line feed in order
  90.         mov    al, 0ah            ; to terminate this line.
  91.         call    PutChar
  92.  
  93.  
  94. Quit:        mov    ah, 4ch            ;DOS opcode to quit program.
  95.         int    21h            ;Call DOS.
  96. Main        endp
  97.  
  98. cseg        ends
  99.  
  100. sseg        segment    para stack 'stack'
  101. stk        byte    1024 dup ("stack   ")
  102. sseg        ends
  103.  
  104. zzzzzzseg    segment    para public 'zzzzzz'
  105. LastBytes    byte    16 dup (?)
  106. zzzzzzseg    ends
  107.         end    Main
  108.